package com.ztgf.shopping.api.client.shop;

import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.service.shop.IShopTipService;
import com.ztgf.shopping.models.vo.shop.ShopLittleRedDotVO;
import com.ztgf.shopping.models.vo.shop.ShopTipVO;
import com.ztgf.user.models.dto.UserInfoDTO;
import com.ztgf.user.models.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YUE
 * @create 2020-11-13 9:54
 */
@RestController
@RequestMapping("/api/ShopTip")
@Slf4j
@Api(value = "ShopTipApiController", tags = "商城个人中心提示信息")
public class ShopTipApiController {

    @DubboReference
    private IShopTipService shopTipService;
    @DubboReference
    private IUserInfoService userInfoService;

    @PostMapping("/getShopTipNum")
    @ApiOperation(value = "店铺id", notes = "店铺id")
    @ApiImplicitParams({@ApiImplicitParam(name = "shopId", value = "店铺id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "type", value = "1买家 2卖家", required = true, dataType = "Integer")})
    public Result<ShopTipVO> getShopTipNum(Long shopId, Integer type) {
        if (shopId == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        if (type == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        ShopTipVO shopTipNum = shopTipService.getShopTipNum(shopId, type);
        ShopLittleRedDotVO shopLittleRedDot = shopTipService.getShopLittleRedDot(shopId, type);
        shopTipNum.setInventoryManagementNum(shopLittleRedDot.getInventoryManagementNum());
        shopTipNum.setGoodsRemovedNum(shopLittleRedDot.getGoodsRemovedNum());
        shopTipNum.setGoodsCheckNum(shopLittleRedDot.getGoodsCheckNum());
        shopTipNum.setUndoneOrderNum(shopLittleRedDot.getUndoneOrderNum());
        shopTipNum.setNumberOfQualifications(shopLittleRedDot.getNumberOfQualifications());
        shopTipNum.setAbandonContractNum(shopLittleRedDot.getAbandonContractNum());
        shopTipNum.setInvoiceNum(shopLittleRedDot.getInvoiceNum());
        shopTipNum.setUndoneInquiryOrderNum (shopLittleRedDot.getUndoneInquiryOrderNum ());
        UserInfoDTO userInfoDTO = new UserInfoDTO ();
        userInfoDTO = userInfoService.selectByShopId(shopId);
        if(userInfoDTO != null){
            shopTipNum.setLookPurchaseType (userInfoDTO.getLookType ());
        }
        return new Result<>(shopTipNum);
    }

    @PostMapping(value = "/updateRedDot")
    @ApiOperation(value = "修改小红点已查看", notes = "修改小红点已查看")
    public Result updateRedDot(Long shopId, Integer type, Integer flag) {
        shopTipService.updateRedDot(shopId, type, flag);
        return new Result<>();
    }

}
